layui.define(['setter', 'helper'], function (exports) {

    var setter = layui.setter
        , helper = layui.helper
        , user = {}

    user.token = function() {
        var d = layui.data(setter.tableName);
        return helper.getValue(d, "token", undefined);
    }

    user.info = function() {
        var d = layui.data(setter.tableName);
        return helper.getValue(d, "user", null);;
    }

    user.isGuest = function() {
        var token = user.token();
        return !token;
    }

    user.login = function(token, info) {
        layui.data(setter.tableName, { key: 'token', value: token });
        layui.data(setter.tableName, { key: 'info', value: info });
    }

    user.logout = function() {
        layui.data(setter.tableName, { key: 'token', remove: true });
        layui.data(setter.tableName, { key: 'info', remove: true });
    }

    exports('user', user)

});

